
// table_OA5.do
* August 2023
* merge the sensitivity checks of the stickiness measure and look at their correlation with the baseline estimates. 
* produce table_OA5 and figure _OA10 

global firstyear 1996 
global lastyear 2006
cd $rspath 

	use rs_transac19962006, clear
	rename rs_total transac_bhs
	keep transac*  hs6
	collapse (mean) transac_b  , by(hs6)
	save tmp, replace 

	use rs_baseline_id_conc$firstyear$lastyear, clear 
	merge m:1 hs6 using tmp 
	keep if _m==3 
	collapse (mean) rs* transac , by(hs6) 
	merge 1:1 hs6 using rs_19962006_quintile 
	drop _m 
	merge 1:1 hs6 using rs_19962006_iso2 
	drop _m 
	merge 1:1 hs6 using  rs_19962006topdecile
	drop _m 
	merge 1:1 hs6 using rs_19962006_leftc 
	drop _m
	merge 1:1 hs6 using rs_19962006total
 	drop _m	
	g hs6 = hs6_2002 
	merge 1:1 hs6 using rs_20112017
	drop if _m==2
	drop _m 
	
	foreach j in DE BE IT ES GB{
	merge 1:1 hs6_2002 using rs_19962006`j' 
	drop _m 
	}
	
	g hs4=substr(hs6,1,4)
	destring hs4, replace 
	merge m:1 hs4 using rs_19962006hs4
	
putexcel set $outputpath/table_online_5.xls, replace


putexcel B1="measure"
putexcel C1="corr w. baseline"
putexcel D1="IQR"
putexcel E1="# prod"

local j=2
foreach i in rs_hs6_b rs_hs6quintile rs_hs6iso rs_topdecile  rs_alpha rs_nosize dur rs_cty transac_bhs rs_lftc rs_total rs_hs4  rs_hs6DE rs_hs6BE rs_hs6IT rs_hs6ES rs_hs6GB rs_hs6_20112017b{
putexcel B`j' = "`i'"	
corr rs_hs6_b `i'	[aw=1/rs_hs6_se]
local rho = r(rho)
putexcel C`j' =`rho'
tabstat `i', s(iqr n) save
mat total = r(StatTotal) 
return list
local stat1=total[1,1] 
putexcel D`j'=`stat1'
local stat2=total[2,1]  
putexcel E`j'=`stat2'
local j = `j'+1
}


set scheme s1color
gr tw (scatter rs_hs6_20112017b rs_hs6_b, m(p)) (lfit rs_hs6_20112017b rs_hs6_b [aw=1/rs_hs6_se], ) (lfit rs_hs6_20112017b rs_hs6_b, lp(dash) lc(grey)) ,   legend(off) xtitle("RS measure, 1996-2006") ytitle("RS measure, 2011-2017")
graph export $outputpath/figure_OA10.pdf, replace



use rs_baseline_id_conc19962006, clear
g hs4 =substr(hs6_2002,1,4) 
collapse (mean) rs_hs6* ,by(hs4)
merge 1:1 hs4 using stickiness_colombia
 bys _m:   sum rs_hs6_b ,d
keep if _m==3
g we=abs(1/rs_hs6_se)
pwcorr rs_hs6_b rs_co dur, sig
pwcorr rs_hs6_b rs_co dur [w=we], sig


	local j=20
foreach i in rs_co {
putexcel B`j' = "`i'"	
corr rs_hs6_b `i'	[aw=we]
local rho = r(rho)
putexcel C`j' =`rho'
tabstat `i', s(iqr n) save
mat total = r(StatTotal) 
return list
local stat1=total[1,1] 
putexcel D`j'=`stat1'
local stat2=total[2,1]  
putexcel E`j'=`stat2'
local j = `j'+1
}


	
	
	